package com.liao.badminton.controller;


import com.liao.badminton.code.ResponseRest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;

@Controller
@RestController("/files")
public class FileDealController {
//    @GetMapping("/download")
//    @PreAuthorize("@ss.hasPermission('file/download')")
//    public void download(HttpServletResponse response){
//        Set< Map<String,Object>> headers = new HashSet<>();
//        TreeMap<String,Object> list = new TreeMap<>();
//        list.put("对战记录不能为空",null);
//        list.put("群id",null);
//        list.put("对战时间",null);
//        list.put("是否加入统计：0否，1是",null);
//        headers.add(list);
//        OutputStream out = null;
//        try (ExcelWriter writer = ExcelUtil.getWriter()) {
//            writer.write(headers, true);// 写入数据
//            response.setContentType("application/vnd.ms-excel;charset=utf-8");
//            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("对局模板.xlsx", "UTF-8"));
//            out = response.getOutputStream();// 获取流
//            writer.flush(out, true); // 将数据流输出到文件
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        IoUtil.close(out);// 流的操作要关闭
//    }


    @PostMapping("/upload")
    @ResponseBody
    @PreAuthorize("@ss.hasPermission('bpm/process-definition/query')")
    public ResponseRest upload(@PathParam("files") MultipartFile file) {
        return ResponseRest.suc("upload", "上传成功！！");
    }
}


